<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>所有用户的借阅情况</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
        }
        table {
            width: 100%;
            border-collapse: collapse;
        }
        th, td {
            padding: 8px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }
        th {
            background-color: #f2f2f2;
        }
    </style>
</head>
<body>
<h1>所有用户的借阅情况</h1>
<table id="borrowRecordsTable">
    <thead>
    <tr>
        <th>借阅用户</th>
        <th>图书名</th>
        <th>图书类别</th>
        <th>作者</th>
        <th>借阅日期</th>
        <th>还书日期</th>
    </tr>
    </thead>
    <tbody>
    <!-- 借阅记录将通过AJAX动态插入这里 -->
    </tbody>
</table>

<script>
    $(document).ready(function() {
        $.ajax({
            url: '/api/v1/borrow-records/list-all',
            method: 'GET',
            contentType: 'application/json',
            success: function(data) {
                var records = data;
                var tbody = $('#borrowRecordsTable tbody');
                records.forEach(function(record) {
                    tbody.append(
                        '<tr>' +
                        '<td>' + record.username + '</td>' +
                        '<td>' + record.bookName + '</td>' +
                        '<td>' + record.category + '</td>' +
                        '<td>' + record.author + '</td>' +
                        '<td>' + record.borrowDate + '</td>' +
                        '<td>' + (record.returnDate || '未还') + '</td>' +
                        '</tr>'
                    );
                });
            },
            error: function(xhr, status, error) {
                console.error('获取借阅记录失败:', error);
            }
        });
    });
</script>
</body>
</html>